/**********************************************
*  Classes:   GameApp
*  Desc:      Singleton class. Runs game
*			  
*  Author:    Vaios Kalpias-Ilias (C) 2008-2009
***********************************************/

#ifndef GAMEAPP_H
#define GAMEAPP_H

#include <windows.h>
#include "InputManager.h"
#include "SmartPointer.h"

class EventManager;
class ScriptManager;
class CdnRenderer;

class GameApp
{
public:
	
	// gets single instance
	static GameApp* GetInstance();
	// destroys single instance
	static void Destroy();

	// starts main loop
	int Start(HINSTANCE& hInstance);
	// quits app
	void Quit();
	// windows message pump handler
    static LRESULT CALLBACK MsgHandler(HWND hwnd, 
		UINT message, WPARAM wparam, LPARAM lparam);

private:

	// single instance
	static GameApp* m_pInstance;
	// ptr to input manager
	InputManager* m_pInputMgr;
	// ptr to event manager
	EventManager* m_pEventMgr;
	// ptr to script manager
	ScriptManager* m_pScriptMgr;
	// ptr to renderer
	CdnRenderer* m_pRenderer;
	// delta time
	float m_fDeltaTime;
	// const time step for physics
	const float m_fcTimeStep;
	// speed modifier for making the simulation run 
	// at a satisfying speed
	const float m_fcSpeedModifier;
	// is a performance timer available
	bool m_bPerfTimer;
	//performance timer frequency
	LONGLONG m_PerfFreq;
	float m_fPerfFreq;
	// time to render next frame
	LONGLONG m_NextTime;
	float m_fNextTime;
	// last time
	LONGLONG m_LastTime;
	float m_fLastTime;	
	// time accumulator
	float m_fTimeAccum;
	// max delta time
	const float m_fcMaxDT;
	// total time
	float m_fTotalTime;
	// is application active
	bool m_bActive;

	// ctor - dtor
	GameApp();
	~GameApp();

	// Initializes app
	bool Init(HINSTANCE &hInstance);
	// Shuts down app
	void ShutDown();
	// Runs a game step
	bool Run();
	// Resets app
	void Reset();
	// Initializes timers
	void InitializeTimers();
	// Initializes managers
	bool InitializeManagers();
	// Creates a scene
	bool SetupScene();
	// Handles user input
	void ProcessInput();
	// Performs AI
	void DoAI();
	// Updates timers
	void UpdateTime();
	// Performs physics step
	void DoPhysics();
	// Updates Frame
	void UpdateFrame();
	// Renders Frame
	void RenderFrame();
	// Renders UI
	void RenderScreenItems();

	
};

SmartPointer(GameApp);

#endif